package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.mapper.StrategyCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrateCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StrategyCommentServiceImpl implements IStrateCommentService {
    @Autowired
    private StrategyCommentMapper strategyCommentMapper;
    @Override
    public List<StrategyComment> queryStrateCommentByStrategyId(Long strategyId) {
        return strategyCommentMapper.queryStrateCommentByStrategyId(strategyId);
    }

    @Override
    public List<StrategyComment> queryStrategyCommentsByStrategyIdAndState(Long strategyId, Integer state) {
        return strategyCommentMapper.queryStrategyCommentsByStrategyIdAndState(strategyId, state);
    }

    @Override
    public StrategyComment getStrategyCommentById(Long id) {
        return strategyCommentMapper.selectByPrimaryKey(id);
    }

    @Override
    public Long save(StrategyComment strategyComment) {
        // 默认攻略点评创建时间
        strategyComment.setCreateTime(new Date());
        // 默认攻略点评的状态为待审核
        strategyComment.setState(StrategyComment.STATE_NORMAL);
        // 保存攻略
        strategyCommentMapper.insert(strategyComment);
        return strategyComment.getId();
    }

    /**
     * 查询攻略评论的分页数据
     *
     * @param qo 分页查询条件
     */
    @Override
    public PageInfo query(StrategyCommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<StrategyComment> list = strategyCommentMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void update(StrategyComment strategyComment) {
        strategyCommentMapper.updateByPrimaryKey(strategyComment);
    }


}
